/*
 * @Author: your name
 * @Date: 2021-03-30 12:52:54
 * @LastEditTime: 2021-03-31 14:00:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \my-app-koa\validation\register.js
 */
const Validator = require('validator');
const isEmpty = require("./is-empty.js")
module.exports = function validateProfileInput (data) {
  let errors = {};
  data.handle = !isEmpty(data.handle) ? data.handle : ''
  data.status = !isEmpty(data.status) ? data.status : ''
  data.skills = !isEmpty(data.skills) ? data.skills : ''
  if (!Validator.isLength(data.handle, { min: 2, max: 30 })) {
    errors.handle = "标识长度不能小于2并且大于30"
  }
  if (Validator.isEmpty(data.handle)) {
    errors.handle = "用户名不能为空"
  }
  if (Validator.isEmpty(data.status)) {
    errors.status = "职位不能为空"
  }
  if (Validator.isEmpty(data.skills)) {
    errors.skills = "技能不能为空"
  }

  return {
    errors,
    isValid: isEmpty(errors)
  }
}

